package com.binge.test.builder;

import java.util.ArrayList;

/*
 * 建造者模式
 *
 * */
public abstract class CarTemplate {

    private ArrayList<String> arrayList = new ArrayList<>();

    protected abstract void start();

    protected abstract void stop();

    protected abstract void alarm();

    protected abstract void engineBoom();

    public final void run() {
        for (String action : arrayList) {
            if (action.equalsIgnoreCase("start")) {
                this.start();
            } else if (action.equalsIgnoreCase("stop")) {
                this.stop();
            } else if (action.equalsIgnoreCase("alarm")) {
                if (this.isAlarm()) {
                    this.alarm();
                }
            } else if (action.equalsIgnoreCase("engine boom")) {
                this.engineBoom();
            }
        }
    }

    protected boolean isAlarm() {
        return true;
    }

    public void setSequence(ArrayList<String> arrayList) {
        this.arrayList = arrayList;
    }


}
